﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Net.Mail;

namespace EnvironmentManagerSystem.AEmail
{
    public partial class LocalHost : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SendMailLocalhost();
        }
        public void SendMailLocalhost()
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            msg.To.Add("339239625@qq.com");//可以发送给多人
            msg.CC.Add("339239625@qq.com");//可以抄送给多人
            msg.From = new MailAddress("cmkj_service@163.com", "发件人姓名二", System.Text.Encoding.UTF8);//这三个参数分别是发送人地址(可以随便写)，发件人姓名，编码
            msg.Subject = "邮件标题二";//邮件标题
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
            msg.Body = "邮件内容";//邮件内容
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
            msg.IsBodyHtml = false;//是否是HTML邮件
            msg.Priority = MailPriority.High;//邮件优先级

            SmtpClient client = new SmtpClient();
            //client.Host = "localhost";

            client.Credentials = new System.Net.NetworkCredential("cmkj_service@163.com", "hrbcmkj");//写发送邮件的GMail邮箱和密码
            //client.Port = 587;//GMail使用的端口
            client.Host = "smtp.163.com";
            object userState = msg;
            try
            {
                client.SendAsync(msg, userState);
                //简单一点可以client.Send(msg);
                Jscript.Alert("发送成功！", this);
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                Jscript.Alert("发送邮件出错！", this);
            }
        }
    }
}
